﻿<Window x:Class="JenkinsController.View.ChangeSetView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="500"
        Icon="..\Resources\Moustache.ico" Name="Root">
    
    <Window.Title>
        <MultiBinding StringFormat="{}{0} change set (source controller: {1})">
            <Binding Path="Build.DisplayName" />
            <Binding Path="Build.ChangeSet.SourceControllerKind" />
        </MultiBinding>
    </Window.Title>

    <Grid>
        <ScrollViewer>
            <ItemsControl ItemsSource="{Binding Build.ChangeSet.Items}" AlternationCount="2">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border Padding="5">

                            <Border.Style>
                                <Style TargetType="Border">
                                    <Style.Triggers>
                                        <DataTrigger
                                            Binding="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}"
                                            Value="1">
                                            <Setter Property="Background" Value="#F0F0F0" />
                                        </DataTrigger>

                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="BorderBrush" Value="SteelBlue" />
                                            <Setter Property="BorderThickness" Value="2" />
                                        </Trigger>
                                    </Style.Triggers>

                                    <Setter Property="BorderBrush" Value="Transparent" />
                                    <Setter Property="BorderThickness" Value="2" />
                                </Style>
                            </Border.Style>

                            <Grid>
                                <StackPanel>

                                    <TextBlock Margin="0,0,0,5" FontWeight="Bold">
                                        <Run Text="{Binding Message}" />
                                    </TextBlock>

                                    <TextBlock Margin="0,0,0,5" FontStyle="Italic" Foreground="Blue">

                                        <Run>Commit</Run>
                                        <Run Text="{Binding CommitId}" />
                                        <Run>by</Run>
                                        <Run Text="{Binding Author.FullName}" />
                                    </TextBlock>

                                    <ItemsControl ItemsSource="{Binding Changes}" Margin="10,0,0,0">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock TextWrapping="Wrap">
                                                    <Run>[</Run>
                                                    <Run Text="{Binding ChangeType}" />
                                                    <Run>]</Run>
                                                    <Run Text="{Binding FilePath}" />
                                                </TextBlock>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>

                                <Rectangle Fill="Transparent">
                                    <Rectangle.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="Copy Commit ID"
                                                      Click="OnCopyCommitIdClick"
                                                      Tag="{Binding}" />
                                        </ContextMenu>
                                    </Rectangle.ContextMenu>
                                </Rectangle>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"
                   Visibility="{Binding NoChangeSet, Converter={StaticResource BooleanToVisibilityConverter}}">
            No change set available
        </TextBlock>

    </Grid>
</Window>